<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24" >
            <a-form-model-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectNo">
              <a-input v-model="model.projectNo" placeholder="请输入项目编号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="变更事项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changeOption">
               <a-select v-model="model.changeOption"  placeholder="请选择"
              :options="changeOptionOptions" @change="changeOptionChange" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="变更前内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="oldContent">
              <a-input v-model="model.oldContent" placeholder="请输入变更前内容"  ></a-input>
            </a-form-model-item>
          </a-col>
           <a-col :span="24">
            <a-form-model-item label="变更后内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="newContent">
              <a-input v-model="model.newContent" placeholder="请输入变更后内容"  ></a-input>
            </a-form-model-item>
          </a-col>
            <a-col :span="24">
          <a-form-model-item label="核准日期"  :labelCol="labelCol" :wrapperCol="wrapperCol" prop="changTime">
                  <a-date-picker
                    v-model="model.changTime"
                    valueFormat="YYYY-MM-DD"
                    style="width: 100%"
                    placeholder="请选择核准日期"
                  />
                </a-form-model-item>
                    </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HteLibCompanyPushForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           projectNo: [
              { required: true, message: '请输入'},
           ],
           changeOption: [
              { required: true, message: '请选择'},
           ],
           oldContent: [
              { required: true, message: '请输入'},
           ],
           newContent: [
              { required: true, message: '请输入'},
           ],
            changTime: [
              { required: true, message: '请输入'},
           ],
        },
        url: {
          add: "/libraryCompany/hteLibCompanyChange/add",
          edit: "/libraryCompany/hteLibCompanyChange/edit",
          queryById: "/libraryCompany/hteLibCompanyChange/queryById",
          codeInfoList: '/manage/codeInfo/list',
        },
        changeOptionOptions:[],
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      getAction(this.url.codeInfoList, { type: '设立公司变更事项', pageNo:1,pageSize:9999,isdel: 0 })
        .then((res) => {
          if (res.code == 200) {
            var list = res.result
            if (list != null) {
              list.records.map((item) => {
                this.changeOptionOptions.push({ value: item.code, label: item.name })
              })
            }
          } else {
            this.$message.warning('查询设立公司变更事项失败:' + res.message)
          }
        })
        .catch((res) => {
          this.$message.warning('查询设立公司变更事项失败:' + res.message)
        })
    },
    methods: {
       changeOptionChange(value,option) {
      var changeOptionName = option.componentOptions.children[0].text;
      this.$set(this.model, 'changeOptionName', changeOptionName)
    },
      add (record) {
        this.edit(Object.assign({}, record));
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>